
<%@ page import ="com.easyattendance.services.AddMaterialService" %>
<%@ page import ="com.easyattendance.services.AddSectionService" %>
<%@ page import ="com.easyattendance.model.Material" %>
<%@ page import ="com.easyattendance.model.Class" %>
<%@ page import ="com.easyattendance.model.MaterialSection" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Section - Material Settings</title>
<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
<jsp:include page="../includeFiles.jsp" ></jsp:include>

<!-- fooTable Links -->
<link href="../css/footable.core.css" rel="stylesheet" type="text/css" />
<link href="../css/footable.metro.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/public/js/footable.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/public/js/footable.sort.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function () {
		$('.footable').footable();
	});
</script>

</head>

<!--
		Note: Set the body element's class to "left-sidebar" to position the sidebar on the left.
		Set it to "right-sidebar" to, you guessed it, position it on the right.
	-->
	
<% String currentUser = (String) session.getAttribute("currentUser");

	AddSectionService sectionService;	
	String sectionName=null;
	String sectionId=null;
	
	if(currentUser!=null)
	{
		sectionService=new AddSectionService();
		sectionName=sectionService.getSectionBySectionEmail(currentUser).getSection_name();
		sectionId=sectionService.getSectionBySectionEmail(currentUser).getSection_id();
	}	
 
    AddMaterialService addMaterialService = new AddMaterialService();	
    List<MaterialSection> materialSectionList = new ArrayList<MaterialSection>();
	materialSectionList = addMaterialService.listMaterialsBySection(sectionName);
	   
	MaterialSection tempmaterial = null;
	int i=0;					
	Iterator MaterialSectionItr = materialSectionList.iterator();
	
   
%>

<body class="left-sidebar">

<!-- Session check : user logged in or not/ press back button -->
<jsp:include page="../common/checkSession.jsp"></jsp:include>
<jsp:include page="../common/checkSectionRole.jsp" />

	<!-- Wrapper -->
	<div id="wrapper">

		<!-- Content -->
		<div id="content">
			<div id="content-inner">


				<div>
					<form action="addMaterial.jsp">
						<input type="submit" value="Add Material" class="button add_button" tabindex="1">
					</form>
				</div>	
				
				<span class="success_msg">${materialDeleted}</span>
				<span class="error_msg">${materialNotDeleted}</span>
				<span class="error_msg">${invalidChoice}</span>

  		<div >
		      <form name="material" action="${pageContext.request.contextPath}/AddMaterialServlet" class="gridview"> 
				<table name="material" id="tbl_material" class="footable metro-attendance">
                <thead>
                <tr>
                    <th></th>
                    <th data-toggle="true">
                        Material Id
                    </th>
                    <th data-toggle="true">
                        Class Id
                    </th>
                  
                    <th data-toggle="true" data-sort-ignore="true">
                        Material Type
                    </th>
                    
                  <!--  <th data-toggle="true" data-sort-ignore="true">
                        Path
                    </th>   
                    <th data-sort-ignore="true">
                    </th> -->
                </tr>
                </thead>
              <tbody>
		
		<%if(materialSectionList!=null)
		{ %>
			<% while(MaterialSectionItr.hasNext()) { i++;%>
						 <% try {
									tempmaterial = (MaterialSection) MaterialSectionItr.next();
								} 
								catch(Exception ex){
									ex.printStackTrace();
								}%> 
								
				<tr>				
					
					<td>
						<input type="checkbox" id="checkbox" name="checkbox<%=i%>" class="chk" value="<%=(i-1)%>">
					</td>
					
					<td data-value="<%=tempmaterial.getMaterial_id() %>">
						<input type="text" id="material_id" name="material_id" value="<%=tempmaterial.getMaterial_id()%>" readonly="readonly" />
					</td>
				
				<%  Class class_obj=tempmaterial.getClassObj();
				  if(class_obj!=null){ %>	
					<td data-value="<%=tempmaterial.getClassObj().getClass_id() %>">
						 <input type="text" id="class_id" name="class_id" value="<%=tempmaterial.getClassObj().getClass_id() %>" readonly="readonly" />	 
					</td>
				<%}else{ %>
					 <td data-value="-">
						 <input type="text" id="class_id" name="class_id" value="-" readonly="readonly" />	 
					</td>
				<%} %>
					<td data-value="<%=tempmaterial.getMaterial().getMaterial_type() %>">
						<input type="text" id="material_type" name="material_type" value="<%=tempmaterial.getMaterial().getMaterial_type()%>" readonly="readonly" />	
					</td>
				
				</tr>	
					
						
			<% } %>
		<% } %>	

	 </tbody>
   </table>
   
   <!--  Hidden fields -->
						
			<input type="hidden" id="section_id" name="section_id" value="<%= sectionId %>"> 		
	  		<input type="hidden" id="action_type" name="action_type" value="delete"> 
		  	<input type="hidden" id="user_type" name="user_type" value="section"> 
		  		
		 	<input type="submit" id="deleteMaterial" value="Delete Selected Materials" class="button add_button"  onclick="return confirm('Are you sure?')">	
				
  </form> 
</div>			 			
							
				
			</div>
		</div>

		<!-- Sidebar -->
		<div id="sidebar">

			<!-- Sidebar Header - Logo & Name -->
			<jsp:include page="../common/sidebarHeader.jsp" ></jsp:include>

			<jsp:include page="sectionMenu.jsp" />
							
			<!-- Sidebar Footer Content -->
			<jsp:include page="../common/sidebarFooter.jsp" />

		</div>

	</div>
	<script type="text/javascript">
		$(function(){
			$("#materialSettings").addClass("current_page_item");
		});
	</script>

</body>
</html>